﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Pointandclick.Objects
{
    class MouseInteractive
  {
        protected Texture2D image;
        public Texture2D Image
        {
            get { return image; }
            set {image = value;}
        }

        protected Rectangle rectangle;
        public Rectangle Rectangle
        {
            get { return rectangle;}
            set { rectangle = value; }
        }

        public MouseInteractive(Texture2D image, Point position)
        {
            this.image = image;
            rectangle = new Rectangle(position.X, position.Y, image.Bounds.Width, image.Bounds.Height);
        }


        /// <summary>
        /// Returns true if the mouse was pressed while inside the objects colision rectangle
        /// </summary>
        /// <param name="mouse"></param>
        /// <param name="gameTime"></param>
        /// <returns></returns>
        public bool ClickedOn()
        {
            //The oldMouse verification is to avoid dragging the mouse into the rectangle and triggering the action
            if (rectangle.Contains(new Point(Inputs.Mouse.X, Inputs.Mouse.Y))
                && (Inputs.OldMouse.LeftButton == ButtonState.Released) && (Inputs.Mouse.LeftButton == ButtonState.Pressed))
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// Draws the Object
        /// </summary>
        /// <param name="spriteBatch">spriteBatch being used</param>
        public void Draw(SpriteBatch spriteBatch, Color color)
        {
            spriteBatch.Draw(image, rectangle, color);
        }
    }
}
